<?php
    // ==========================================
    // = compressed prototype and scriptaculous =
    // ==========================================
    #ini_set('display_errors',1);
    #error_reporting(E_ALL);
    // start headers
    header("Content-type: text/javascript; charset: UTF-8");
    header("Vary: Accept-Encoding");
    header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600 * 24 * 10)) . " GMT");
  
    // check if browser enjoys unzipping its pants.
    if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) 
    {
        // check cache
        require(dirname(dirname(__FILE__)).'/../pixel/vendor/cache/Lite.php');
        $options = array( 
                         'cacheDir'=> dirname(dirname(__FILE__)).'/../pixel/cache/',
                         'lifeTime'=> (3600 * 24 * 10)
                        );            
        $Cache_Lite = new Cache_Lite($options);                      
        if ( $compressed = $Cache_Lite->get('prototype') )
        {
            $js =& $compressed;
        } else {        
            $js  = file_get_contents(realpath('prototype/prototype.js'));
            $js .= "\nvar Scriptaculous = { Version: '1.7.1_beta2'}\n";
            $js .= file_get_contents(realpath('scriptaculous/builder.js'));
            $js .= file_get_contents(realpath('scriptaculous/effects.js'));
            $js .= file_get_contents(realpath('scriptaculous/dragdrop.js'));
            $js .= file_get_contents(realpath('scriptaculous/controls.js'));
            $js .= file_get_contents(realpath('scriptaculous/slider.js'));
        
            $js = gzencode($js, 9, FORCE_GZIP);
            $Cache_Lite->save($js);
        }
                
        // Check for gzip header or norton internet securities
        if ( (strpos(strtolower($_SERVER['HTTP_ACCEPT_ENCODING']),'gzip') !== false 
              || isset($_SERVER['---------------']))
             && function_exists('ob_gzhandler') 
             && !ini_get('zlib.output_compression')) 
        {        	
        	header("Content-Encoding: gzip");
        	echo $js;
    	}
	} else {
	    ob_start("ob_gzhandler"); // will check if browser supports it as well.
	    echo file_get_contents(realpath('prototype/prototype.js'));
	    echo file_get_contents(realpath('scriptaculous/scriptaculous.js'));
	}
    
?>